package com.bear.cmcc.NetTestHTTP.util;

import com.bear.cmcc.NetTestHTTP.component.CityBean;

import java.util.Comparator;

@SuppressWarnings("rawtypes")
public class SortCityStringSpeed implements Comparator{
	public final static int cityTDSort=0x0040;
	public final static int city2GSort=0x0050;
	public final static int UP = 1;
    public final static int DOWN = -1;
    private int state;
    private int flag;
   
    /**
     * 2G排序
     * @param state 排序状态值
     */
    public SortCityStringSpeed(int state,int flag) {
        this.state = state;
        this.flag=flag;
    }
    
	public int compare(Object obj1, Object obj2) {
		CityBean ps1 = (CityBean)obj1;
		CityBean ps2 = (CityBean)obj2;
		if (state == SortCityStringSpeed.DOWN) {
			switch(flag){
				case cityTDSort:
					return sortDonw(ps1.getDownSpeed(), ps2.getDownSpeed());
				case city2GSort:
					return sortDonw(ps1.getDownSpeed(), ps2.getDownSpeed());
			}
		}	
		switch(flag){
			case cityTDSort:
				return sortUp(ps1.getDownSpeed(), ps2.getDownSpeed());
		}
		return sortUp(ps1.getDownSpeed(), ps2.getDownSpeed());
	}
	
	/**
	 * 升序
	 * @param sp1
	 * @param sp2
	 * @return
	 */
	private int sortUp(int sp1,int sp2)
	{
		int d1=sp1,d2=sp2;
//		try{
//			d1 = Double.valueOf(sp1);
//			d2 = Double.valueOf(sp2);	
//		} catch (Exception e) {
//			e.printStackTrace();
//		}
		
		if((d1-d2) < 0)
			return -1;
		else if((d1-d2) > 0)
			return 1;
		else
			return 0;
	}
	
	/**
	 * 降序
	 * @param sp1
	 * @param sp2
	 * @return
	 */
	private int sortDonw(int sp1,int sp2)
	{
		int d1=sp1,d2=sp2;
//		try{
//			d1 = Double.valueOf(sp1);
//			d2 = Double.valueOf(sp2);	
//		} catch (Exception e) {
//			e.printStackTrace();
//		}
		
		if((d1-d2) > 0)
			return -1;
		else if((d1-d2) < 0)
			return 1;
		else
			return 0;
	}

}
